/**
 * @author: YanYu
 * @date: 2022-09-24 21:12:15
 * @Version：1.0.0
 */
import api from "../../apis/api";

export default {
  state: {
    name: '',
    sex: '',
    age: '',
    maritalStatus: '',
    nationality: '',
    hometown: '',
    birthplace: '',
    profession: '',
    //工作单位
    employer: '',
    currentAddress: '',
    phone: '',
    admissionTime: '',
    recordTime: '',
    historyNarrator: '',
    reliability: '',
    mainSuit: '',
    hpi: '',
    pastHistory: '',
    systemReview: '',
    personalHistory: '',
    marriageHistory: '',
    menstruationAndFertilityHistory: '',
    familyHistory: '',
    physicalCheck: '',
    auxiliaryExamination: '',
    summary: ''
  },
  getters: {
    getRecordInfo(state) {
      return state
    }
  },
  mutations: {
    setName(state, data) {
      state.name = data
    },
    setSex(state, data) {
      state.sex = parseInt(data) === 0 ? "女" :parseInt(data) === 1? "男" : ''
    },
    setAge(state, data) {
      state.age = data
    },
    setMaritalStatus(state, data) {
      state.maritalStatus = data
    },
    setNationality(state, data) {
      state.nationality = data
    },
    setHometown(state, data) {
      state.hometown = data
    },
    setBirthplace(state, data) {
      state.birthplace = data
    },
    setProfession(state, data) {
      state.profession = data
    },
    setEmployer(state, data) {
      state.employer = data
    },
    setCurrentAddress(state, data) {
      state.currentAddress = data
    },
    setPhone(state, data) {
      state.phone = data
    },
    setAdmissionTime(state, data) {
      state.admissionTime = data
    },
    setRecordTime(state, data) {
      state.recordTime = data
    },
    setHistoryNarrator(state, data) {
      state.historyNarrator = data
    },
    setReliability(state, data) {
      state.reliability = data
    },
    setMainSuit(state, data) {
      state.mainSuit = data
    },
    setHpi(state, data) {
      state.hpi = data
    },
    setPastHistory(state, data) {
      state.pastHistory = data
    },
    setSystemReview(state, data) {
      state.systemReview = data
    },
    setPersonalHistory(state, data) {
      state.personalHistory = data
    },
    setMarriageHistory(state, data) {
      state.marriageHistory = data
    },
    setMenstruationAndFertilityHistory(state, data) {
      state.menstruationAndFertilityHistory = data
    },
    setFamilyHistory(state, data) {
      state.familyHistory = data
    },
    setPhysicalCheck(state, data) {
      state.physicalCheck = data
    },
    setAuxiliaryExamination(state, data) {
      state.auxiliaryExamination = data
    },
    setSummary(state, data) {
      state.summary = data
    }
  },
  actions: {
    async setRecordInfo({commit}, id) {
      const result = await api.getMediaInfo(id)
      const {data} = result
      if (result.code === 200) {
        commit("setName", data.name);
        commit("setAge", data.age);
        commit("setSex", data.sex);
        commit("setMaritalStatus", data.maritalStatus);
        commit("setNationality", data.nationality);
        commit("setHometown", data.hometown);
        commit("setBirthplace", data.birthplace);
        commit("setProfession", data.profession);
        commit("setEmployer", data.employer);
        commit("setCurrentAddress", data.currentAddress);
        commit("setPhone", data.phone);
        commit("setAdmissionTime", data.admissionTime);
        commit("setRecordTime", data.recordTime);
        commit("setHistoryNarrator", data.historyNarrator);
        commit("setReliability", data.reliability);
        commit("setMainSuit", data.mainSuit);
        commit("setHpi", data.hpi);
        commit("setPastHistory", data.pastHistory);
        commit("setSystemReview", data.systemReview);
        commit("setPersonalHistory", data.personalHistory);
        commit("setMarriageHistory", data.marriageHistory);
        commit("setMenstruationAndFertilityHistory", data.menstruationAndFertilityHistory);
        commit("setFamilyHistory", data.familyHistory);
        commit("setPhysicalCheck", data.physicalCheck);
        commit("setAuxiliaryExamination", data.auxiliaryExamination);
        commit("setSummary", data.summary);
      }

    },
    async addRecordInfo({commit}) {
      commit("setName", '');
      commit("setAge", '');
      commit("setSex", '');
      commit("setMaritalStatus", '');
      commit("setNationality", '');
      commit("setHometown", '');
      commit("setBirthplace", '');
      commit("setProfession", '');
      commit("setEmployer", '');
      commit("setCurrentAddress", '');
      commit("setPhone", '');
      commit("setAdmissionTime", '');
      commit("setRecordTime", '');
      commit("setHistoryNarrator", '');
      commit("setReliability", '');
      commit("setMainSuit", '');
      commit("setHpi", '');
      commit("setPastHistory", '');
      commit("setSystemReview", '');
      commit("setPersonalHistory", '');
      commit("setMarriageHistory", '');
      commit("setMenstruationAndFertilityHistory", '');
      commit("setFamilyHistory", '');
      commit("setPhysicalCheck", '');
      commit("setAuxiliaryExamination", '');
      commit("setSummary", '');
    }
  }
}
